package Algorithm.set;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

//并集
public class Union {
    int[] a;
    int len_a;
    int[] b;
    int len_b;
    Union(int[] a,int[] b){
        this.a =a;
        this.len_a = a.length;
        this.b =b;
        this.len_b = b.length;
    }
    public Set<Integer> solution(){
        Set<Integer> hs = new HashSet<Integer>();
        for(int i=0;i<len_a;i++){
            hs.add(a[i]);
        }
        for(int i=0;i<len_b;i++){
            hs.add(b[i]);
        }
        return hs;
    }
    public static void main(String[] args) {
        int[] a = new int[]{0,3,5,6,9,15,7};
        int[] b = new int[]{8,9,14,15,3,0};
        Union un  = new Union(a,b);
        Set hs2 = un.solution();
        Iterator it = hs2.iterator();
        while(it.hasNext()){
            System.out.print(it.next()+" ");
        }
    }
}
